package at.jsug.topicvoting.gwt1.client.view.table;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;

public abstract class GridColumnRenderAdapter<E> implements ITableColumnRenderer<E> {

	
	public String renderAsString(E entity) {
		return null;
	}
	

	public Widget renderAsWidget(E entity) {
		return null;
	}
	
	
	public final void autoRenderOn(FlexTable grid, int row, int col, E entity) {
		
		final String stringRendering = this.renderAsString(entity);
		if(stringRendering != null) {
			grid.setText(row, col, stringRendering);
			return;
		}
		
		final Widget widgetRendering = this.renderAsWidget(entity);
		if(widgetRendering != null) {
			grid.setWidget(row, col, widgetRendering);
			return;
		}
		
		throw new RuntimeException("autoRenderOn failed!");
	}
	
	
}
